Cleanup code to reconnect domain control channel after xend restart.
Based on code by Mike Wray.
staticforward PyTypeObject xu_port_type;
-static PyObject *xu_port_new(PyObject *self, PyObject *args)
+static PyObject *xu_port_new(PyObject *self, PyObject *args, PyObject *kwds)
{
xu_port_object *xup;
u32 dom;
int port1 = 0, port2 = 0;
- if ( !PyArg_ParseTuple(args, "i|ii", &dom, &port1, &port2) )
+ static char *kwd_list[] = { "dom", "local_port", "remote_port", NULL };
+
+ if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|ii", kwd_list,
+ &dom, &port1, &port2) )
return NULL;
xup = PyObject_New(xu_port_object, &xu_port_type);
"Create a new notifier." },
{ "message", xu_message_new, METH_VARARGS,
"Create a new communications message." },
- { "port", xu_port_new, METH_VARARGS,
+ { "port", (PyCFunction)xu_port_new, METH_VARARGS | METH_KEYWORDS,
"Create a new communications port." },
{ "buffer", xu_buffer_new, METH_VARARGS,
"Create a new ring buffer." },
def consoles(self):
return daemon.get_consoles()
- def console_create(self, dom, console_port=None, remote_port=0):
- consinfo = daemon.console_create(dom, console_port=console_port,
- remote_port=remote_port)
+ def console_create(self, dom, console_port=None):
+ consinfo = daemon.console_create(dom, console_port=console_port)
return consinfo
def console_get(self, id):
@param ramdisk: kernel ramdisk
@param cmdline: kernel commandline
"""
- #self.init_domain()
+
+ self.create_channel()
if self.console:
self.console.registerChannel()
else:
self.console = xendConsole.console_create(
- self.dom, console_port=self.console_port, remote_port=1)
+ self.dom, console_port=self.console_port)
self.build_domain(ostype, kernel, ramdisk, cmdline)
self.image = kernel
self.ramdisk = ramdisk
self.cmdline = cmdline
+ def create_channel(self):
+ """Create the channel to the domain.
+ If saved info is available recreate the channel using the saved ports.
+
+ @return: channel
+ """
+ local = 0
+ remote = 1
+ if self.savedinfo:
+ consinfo = sxp.child(self.savedinfo, "console")
+ if consinfo:
+ local = int(sxp.child_value(consinfo, "local_port", 0))
+ remote = int(sxp.child_value(consinfo, "remote_port", 1))
+ return xend.createDomChannel(self.dom, local_port=local,
+ remote_port=remote)
+
def create_devices(self):
"""Create the devices for a vm.
def getDomChannel(self, dom):
"""Get the channel to a domain.
- dom domain
-
- returns channel (or None)
+ @param dom: domain
+ @return: channel (or None)
"""
return self.channelF.getDomChannel(dom)
+ def createDomChannel(self, dom, local_port=0, remote_port=0):
+ """Get the channel to a domain, creating if necessary.
+
+ @param dom: domain
+ @param local_port: optional local port to re-use
+ @param remote_port: optional remote port to re-use
+ @return: channel
+ """
+ return self.channelF.domChannel(dom, local_port=local_port,
+ remote_port=remote_port)
+
def blkif_create(self, dom, recreate=0):
"""Create or get a block device interface controller.
def netif_get(self, dom):
return self.netifCF.getControllerByDom(dom)
- def console_create(self, dom, console_port=None, remote_port=0):
+ def console_create(self, dom, console_port=None):
"""Create a console for a domain.
"""
console = self.consoleCF.getControllerByDom(dom)
if console is None:
- console = self.consoleCF.createController(dom, console_port,
- remote_port=remote_port)
+ console = self.consoleCF.createController(dom, console_port)
return console
def consoles(self):
del self.channels[idx]
self.notifier.unbind(idx)
- def domChannel(self, dom, remote_port=0):
+ def domChannel(self, dom, local_port=0, remote_port=0):
"""Get the channel for the given domain.
Construct if necessary.
"""
chan = self.getDomChannel(dom)
if not chan:
- chan = Channel(self, dom, remote_port=remote_port)
+ chan = Channel(self, dom, local_port=local_port,
+ remote_port=remote_port)
self.addChannel(chan)
return chan
"""
self.delChannel(channel.idx)
- def createPort(self, dom, remote_port=0):
+ def createPort(self, dom, local_port=0, remote_port=0):
"""Create a port for a channel to the given domain.
+ If only the domain is specified, a new channel with new port ids is
+ created. If one port id is specified and the given port id is in use,
+ the other port id is filled. If one port id is specified and the
+ given port id is not in use, a new channel is created with one port
+ id equal to the given id and a new id for the other end. If both
+ port ids are specified, a port is reconnected using the given port
+ ids.
+
+ @param dom: domain
+ @param local: local port id to use
+ @type local: int
+ @param remote: remote port id to use
+ @type remote: int
+ @return: port object
"""
- return xu.port(dom, 0, remote_port)
+ return xu.port(dom, local_port=int(local_port),
+ remote_port=int(remote_port))
def channelFactory():
"""Singleton constructor for the channel factory.
are multiplexed over the channel (console, block devs, net devs).
"""
- def __init__(self, factory, dom, remote_port=0):
+ def __init__(self, factory, dom, local_port=0, remote_port=0):
"""Create a channel to the given domain using the given factory.
Do not call directly, use domChannel on the factory.
# Domain.
self.dom = int(dom)
# Domain port (object).
- self.port = self.factory.createPort(dom, remote_port=remote_port)
+ self.port = self.factory.createPort(dom, local_port=local_port,
+ remote_port=remote_port)
# Channel port (int).
self.idx = self.port.local_port
# Registered devices.
self.loseConnection()
def write(self, data):
- #if not self.connected: return -1
self.transport.write(data)
return len(data)
"""Factory for creating console controllers.
"""
- def createController(self, dom, console_port=None, remote_port=0):
+ def createController(self, dom, console_port=None):
if console_port is None:
console_port = CONSOLE_PORT_BASE + dom
for c in self.getControllers():
if c.console_port == console_port:
raise XendError('console port in use: ' + str(console_port))
- console = ConsoleController(self, dom, console_port,
- remote_port=remote_port)
+ console = ConsoleController(self, dom, console_port)
self.addController(console)
log.info("Created console id=%s domain=%d port=%d",
console.idx, console.dom, console.console_port)
STATUS_CONNECTED = 'connected'
STATUS_LISTENING = 'listening'
- def __init__(self, factory, dom, console_port, remote_port=0):
- controller.Controller.__init__(self, factory, dom,
- remote_port=remote_port)
+ def __init__(self, factory, dom, console_port):
+ controller.Controller.__init__(self, factory, dom)
self.addMethod(CMSG_CONSOLE, 0, None)
self.status = self.STATUS_NEW
self.addr = None
@type responders: {int:Responder}
"""
- def __init__(self, remote_port=0):
+ def __init__(self):
self.channelFactory = channel.channelFactory()
self.majorTypes = {}
self.dom = None
self.idx = None
self.responders = {}
self.timeout = 10
- self.remote_port = remote_port
def setTimeout(self, timeout):
self.timeout = timeout
channel to our domain. Once we have registered, the channel
will call requestReceived or responseReceived for our messages.
"""
- self.channel = self.channelFactory.domChannel(self.dom,
- self.remote_port)
+ self.channel = self.channelFactory.domChannel(self.dom)
self.idx = self.channel.getIndex()
if self.majorTypes:
self.channel.registerDevice(self.getMajorTypes(), self)
@type idx: String
"""
- def __init__(self, factory, dom, remote_port=0):
- CtrlMsgRcvr.__init__(self, remote_port=remote_port)
+ def __init__(self, factory, dom):
+ CtrlMsgRcvr.__init__(self)
self.factory = factory
self.dom = int(dom)
self.channel = None